import com.four.bmm.dao.INewsDao;
import com.four.bmm.entity.BlockItem;
import com.four.bmm.entity.News;
import com.four.bmm.service.NewsService;
import com.four.bmm.util.DateUtil;
import com.four.bmm.util.SqlSessionFactoryUtil;
import org.apache.ibatis.session.SqlSession;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;

import java.util.List;

public class NewsTestDemo {
    SqlSession session = null;
    INewsDao newsDao = null;

    @Before
    public void init() {
        session = SqlSessionFactoryUtil.getSqlSession();
        newsDao = session.getMapper(INewsDao.class);
    }

    NewsService newsService = new NewsService();

    @Test
    public void GetAllNews() {

    }

    @Test
    public void setNews() {
        News news = new News();
        news.setTitle("gqfgqqqf");
        news.setContent("工期为杂物共和国海关");
        news.setPushtime(DateUtil.getCurrTime());
        boolean b = newsService.setNews(news);
        System.out.println(b);
    }

    @Test
    public void delNews() {
        boolean b = newsService.delNews(7);
        System.out.println(b);
    }

    @Test
    public void updNews() {
        News news = new News();
        news.setTitle("武松");
        news.setPushtime(DateUtil.getCurrTime());
        news.setContent("的潜伏期大幅擦");
        news.setBlockItem(new BlockItem(2));
        news.setNewsid(1);
        boolean b = newsService.updNews(news);
        System.out.println(b);
    }

    @Test
    public void testById() {
        News news = newsDao.getNewsById(2);
        if (news != null) {
            System.out.println(news.getTitle() + "," + news.getUser().getUsername() + "," + news.getBlockItem().getBitemname());
        }
    }
    @Test
    public void testAdd() {
        int num = newsService.addClickCount(1);
        System.out.println(num);
        int num2= newsService.minusClickCount(1);
        System.out.println(num2);
    }

    @Test
    public void testMinus() {
        int num = newsDao.minusClickCount(1);
        System.out.println(num);
    }

    @After
    public void destroy() {
        session.commit();
        session.close();
    }
}
